package bjut.core.scan;

import bjut.core.annotation.Component;
import bjut.core.bean.BeanDefinition;
import cn.hutool.core.util.ClassUtil;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @Author: zhuzhiming
 * @Date: 2022/6/24 16:01
 */
public class ClassPathScanningCandidateComponentProvider {

    public Set<BeanDefinition> findCandidateComponents(String basePackage) {

        LinkedHashSet<BeanDefinition> candidates = new LinkedHashSet<>();

        Set<Class<?>> classes = ClassUtil.scanPackageByAnnotation(basePackage, Component.class);

        for (Class<?> aClass : classes) {
            candidates.add(new BeanDefinition(aClass));
        }

        return candidates;

    }

}
